local luanchang = fk.CreateSkill{
    name = "jin_heg__luanchang",
    tags = { Skill.Limited },
}

Fk:loadTranslationTable{
    ["jin_heg__luanchang"] = "乱常",
    [":jin_heg__luanchang"] = "限定技，一名角色的回合结束时，若存在与你势力相同本回合受到过伤害且存活的角色，或存在于你明置此武将牌后与你势力相同本回合受到过伤害且存活的角色，你可以令当前回合角色将所有手牌当【万箭齐发】使用。",
    ["#jin_heg__luanchang_prompt"] = "乱常：你可令 %dest 将所有手牌当【万箭齐发】使用",

    ["$jin_heg__luanchang1"] = "不杀人，如何彰显朕的威严！",
    ["$jin_heg__luanchang2"] = "这天下的一切，都是朕的！",
}

local H = require "packages.ol_hegemony.util"

luanchang:addEffect(fk.TurnEnd,{
    anim_type = "offensive",
    can_trigger = function (self, event, target, player, data)
        if not player:hasSkill(luanchang.name) or player:usedSkillTimes(luanchang.name, Player.HistoryGame) > 0 or target:isKongcheng() then return end
        local room = player.room
        for _, p in ipairs(room:getAlivePlayers()) do
          if (H.getKingdom(p) ~= "unknown" or p == player) and H.compareExpectedKingdomWith(player, p) then
            if #room.logic:getActualDamageEvents(1, function (e)
              return e.data.to == p
            end, Player.HistoryTurn) > 0 then
              return true
            end
          end
        end
      end,
    on_cost = function (self, event, target, player, data)
      return player.room:askToSkillInvoke(player,{skill_name = luanchang.name, prompt =  "#jin_heg__luanchang_prompt::"..target.id})
    end,
    on_use = function (self, event, target, player, data)
      local room = player.room
      local card = Fk:cloneCard("archery_attack")
      card.skillName = luanchang.name
      card:addSubcards(target:getCardIds("h"))
      local targets = table.filter(room:getOtherPlayers(target), function(p)
          return not target:isProhibited(p, card)
      end)
      room:useVirtualCard("archery_attack", target:getCardIds("h"), target, targets, luanchang.name)
    end,
})

return luanchang